package com.epower.bo.epoweruser.impl;

import javax.annotation.Resource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.epower.base.BaseBO;
import com.epower.bo.epower.commons.Constants;
import com.epower.bo.epoweruser.EpowerUserService;
import com.epower.dao.epoweruser.EpowerUserDAO;
import com.epower.dataobject.EpowerUserDO;
import java.util.List;

/***
 * BO层实现类
 * 
 * @author QuickDev
 * 
 */
@Scope("singleton")
@Component("epowerUserBO")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class EpowerUserServiceImpl extends BaseBO implements EpowerUserService {
	private EpowerUserDAO epowerUserDAO;

	/***
     * 
     */
	@Override
	public EpowerUserDO getEpowerUserByOption(EpowerUserDO epowerUser) {
		return epowerUserDAO.getEpowerUserByOption(epowerUser);
	}

	/***
     * 
     */
	@Override
	public List<EpowerUserDO> getEpowerUserListByOption(EpowerUserDO epowerUser) {
		return epowerUserDAO.getEpowerUserListByOption(epowerUser);
	}

	@Override
	public List<EpowerUserDO> getEpowerUserListPageByOption(EpowerUserDO epowerUser) {
		int totalItem = getEpowerUserCountByOption(epowerUser);
		epowerUser.setTotalItem(totalItem);
		return epowerUserDAO.getEpowerUserListByOption(epowerUser);
	}

	/***
     * 
     */
	@Override
	public EpowerUserDO getEpowerUserById(Integer id) {
		return epowerUserDAO.getEpowerUserById(id);
	}

	/***
     * 
     */
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public boolean deleteEpowerUserById(Integer id) {
		return epowerUserDAO.deleteEpowerUserById(id);
	}

	/***
     * 
     */
	@Override
	public Integer getEpowerUserCountByOption(EpowerUserDO epowerUser) {
		return epowerUserDAO.getEpowerUserCountByOption(epowerUser);
	}

	/***
     * 
     */
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public boolean updateEpowerUserByOption(EpowerUserDO epowerUser) {
		return epowerUserDAO.updateEpowerUserByOption(epowerUser);
	}

	/***
     * 
     */
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public Integer addEpowerUser(EpowerUserDO epowerUser) {
		try {
			Integer id = epowerUserDAO.addEpowerUser(epowerUser);
			return id;
		} catch (Exception e) {
			throw new RuntimeException("service is error");
		}
	}

	/***
	 * 
	 * @getter setter
	 */
	public EpowerUserDAO getEpowerUserDAO() {
		return epowerUserDAO;
	}

	@Resource
	public void setEpowerUserDAO(EpowerUserDAO epowerUserDAO) {
		this.epowerUserDAO = epowerUserDAO;
	}

	@Override
	public EpowerUserDO getUserByUserName(String userName) {
		EpowerUserDO user = new EpowerUserDO();
		user.setStatus(Constants.STATUS_OK);
		user.setType(Constants.USER_COMMON);
		user.setUsername(userName);
		return this.getEpowerUserByOption(user);
	}

}
